package com.clarence.dada.modular.system.dict.controller;

import com.clarence.dada.core.base.PageResult;
import com.clarence.dada.core.base.Result;
import com.clarence.dada.modular.system.dict.entity.req.DictReq;
import com.clarence.dada.modular.system.dict.entity.resp.SysDictResp;
import com.clarence.dada.modular.system.dict.service.DictService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典管理
 *
 * @author GD
 * @since 2020/10/29 14:45
 */
@RestController
@RequestMapping("/system/dict/")
@Tag(name = "字典详情管理", description = "字典详情管理Controller")
public class DictController {

    @Resource
    private DictService dictService;

    /**
     * 添加字典条目
     *
     * @author GD
     * @since 2020/10/29 16:35
     */
    @Operation(summary = "系统字典_新增", description = "新增字典")
    @PostMapping("dictAdd")
    public Result<Void> dictAdd(@RequestBody @Validated(DictReq.add.class) DictReq req) {
        this.dictService.dictAdd(req);
        return Result.SUCCESS;
    }

    /**
     * 删除字典条目
     *
     * @author GD
     * @since 2020/10/29 16:35
     */
    @Operation(summary = "系统字典_删除", description = "删除字典")
    @PostMapping("dictDelete")
    public Result<Void> dictDelete(@RequestBody @Validated(DictReq.delete.class) DictReq req) {
        this.dictService.dictDelete(req);
        return Result.SUCCESS;
    }

    /**
     * 修改字典条目
     *
     * @author GD
     * @since 2020/10/29 16:35
     */
    @Operation(summary = "系统字典_修改", description = "修改字典")
    @PostMapping("dictEdit")
    public Result<Void> dictEdit(@RequestBody @Validated(DictReq.edit.class) DictReq req) {
        this.dictService.dictEdit(req);
        return Result.SUCCESS;
    }

    /**
     * 获取字典详情
     *
     * @author GD
     * @since 2020/10/29 16:35
     */
    @Operation(summary = "系统字典_详情", description = "获取字典详情")
    @GetMapping("dictDetail")
    public Result<SysDictResp> dictDetail(@Validated(DictReq.detail.class) DictReq req) {
        return new Result<>(this.dictService.dictDetail(req));
    }

    /**
     * 获取字典列表
     *
     * @author GD
     * @since 2020/10/29 16:35
     */
    @Operation(summary = "系统字典_列表", description = "获取字典列表")
    @GetMapping("dictList")
    public Result<List<SysDictResp>> dictList(DictReq req) {
        return new Result<>(this.dictService.dictList(req));
    }

    /**
     * 获取字典列表(分页)
     *
     * @author GD
     * @since 2020/10/29 16:35
     */
    @Operation(summary = "系统字典_列表(分页)", description = "获取字典列表(分页)")
    @GetMapping("dictPage")
    public Result<PageResult<SysDictResp>> dictPage(DictReq req) {
        return new Result<>(this.dictService.dictPage(req));
    }

//    /**
//     * 获取树形字典列表
//     *
//     * @author GD
//     * @since 2020/10/29 16:36
//     */
//    @Operation(summary = "系统字典_列表(树)", description = "获取字典列表(树)")
//    @GetMapping("getDictTreeList")
//    public Result<List<TreeDictInfo>> getDictTreeList(@Validated(DictReq.treeList.class) DictReq req) {
//        List<TreeDictInfo> treeDictList = this.dictService.getTreeDictList(dictReq);
//        return new Result<>(treeDictList);
//    }
//
    /**
     * 获取系统配置分组字典列表(分页)（给系统配置界面，左侧获取配置的分类用）
     *
     * @author GD
     * @since 2021/1/25 11:47
     */
    @Operation(summary = "系统字典_获取系统配置分组字典列表", description = "获取系统配置分组字典列表")
    @GetMapping("getConfigGroupPage")
    public Result<PageResult<SysDictResp>> getConfigGroupPage() {
        DictReq req = new DictReq();
        req.setDictTypeCode("config_group");
        return new Result<>(this.dictService.dictPage(req));
    }

}
